package com.letv.android.client.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.letv.android.young.client.R;
import com.letv.core.utils.StatisticsUtils;
import com.letv.datastatistics.util.PageIdConstant;

/**
 * 长时间观看提现dialog
 * 
 * @author zhuqiao
 *
 */
public class LongWatchNoticeDialog extends Dialog {
    private Context mContext;
    private static LongWatchNoticeDialog dialog = null;

    public LongWatchNoticeDialog(Context context, int theme) {
        super(context, theme);
        this.mContext = context;
        initView();
    }

    private void initView() {
        this.setCanceledOnTouchOutside(false);
        View root = View.inflate(getContext(), R.layout.letv_layout_long_watch, null);
        this.setContentView(root, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        TextView iKnow = (TextView) root.findViewById(R.id.textView_i_know);
        iKnow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LongWatchNoticeDialog.this.dismiss();
                StatisticsUtils.staticticsInfoPost(mContext, "0", "c686", null, 1, null, PageIdConstant.fullPlayPage,
                        null, null, null, null, null);
            }
        });
    }

    public static void show(final DismissCallBack callBack, Context context) {
        dialog = new LongWatchNoticeDialog(context, R.style.first_push_style);
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (callBack != null)
                    callBack.dimiss();
            }
        });
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    public static void dismissDialog() {
        try {
            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public interface DismissCallBack {
        void dimiss();
    }
}
